package from_0_to_50;

public class Q002_addTwoNumbers {
    public static void main(String[] args) {
        ListNode head1 = new ListNode(0);    //123
        ListNode head2 = new ListNode(0);    //456   321 + 654 = 975
        ListNode head3 = new ListNode(0);
        Integer carry = 0;
        head1.next = new ListNode(1);
        head2.next = new ListNode(4);
        ListNode pre1 = head1.next;
        ListNode pre2 = head2.next;
        // 赋值
        for (int i = 2; i < 4; i++) {
            pre1.next = new ListNode(i);
            pre1 = pre1.next;
        }
        for (int i = 5; i < 7; i++) {
            pre2.next = new ListNode(i);
            pre2 = pre2.next;
        }
        System.out.println("原始数据：");
        // 显示
        int count1 = 0;
        int count2 = 0;
        pre1 = head1;
        pre2 = head2;
        while (null != pre1.next){
            if(null != pre1.next.next){
                System.out.print(pre1.next.val+"->");
            }
            else
                System.out.print(pre1.next.val);
            count1++;
            pre1 = pre1.next;
        }
        System.out.println();
        System.out.println(count1);
        while (null != pre2.next){
            if(null != pre2.next.next){
                System.out.print(pre2.next.val+"->");
            }
            else
                System.out.print(pre2.next.val);
            count2++;
            pre2 = pre2.next;
        }
        System.out.println();
        System.out.println(count2);
        pre1 = head1;
        pre2 = head2;
        while (null != pre1.next || null != pre2.next){

        }
        while (null != pre2.next){
            if(null != pre2.next.next){
                System.out.print(pre2.next.val+"->");
            }
            else
                System.out.print(pre2.next.val);
            count2++;
            pre2 = pre2.next;
        }

    }

}
class ListNode {
    //属性值
    int val;
    ListNode next;
    //构造函数
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
